<template>
    <div class="mobile-container">
        <!-- 搜索框 -->
        <van-search
        v-model="searchData"
        shape="round"
        background="#2f9296"
        placeholder="请输入项目名称"
        />
        <!-- 项目列表 -->
        <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        >
            <van-cell 
            v-for="(item, index) in projectData" 
            :key="index" 
            :title="item.title + `---` + item.name" 
            :value="item.updatetime_format" 
            :label="item.number"
            @click="() => router.push({path: '/m/sensor', query: {'number': item.number, 'name': item.name}})"
            />
        </van-list>
        <ToolBar/>
    </div>
</template>


<script setup>
import {ref} from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { projectList } from '@/api';
import ToolBar from '@/views/component/ToolBar.vue';

const route = useRoute();
const router = useRouter();
const searchData = ref();
const loading = ref(false);
const finished = ref(false);
const projectData = ref([]);

// 请求数据
const onLoad = async()=>{
    const res = await projectList();
    if (res.status === 2000){
        projectData.value = res.data;
    }else{
        console.log(res.msg);
    };
    loading.value = true; 
    finished.value = true;  
}


</script>

<style scoped>

</style>